# coding: utf-8

import os
import dreamtools as dt
from dreamtools import plot, prt
import numpy as np
import pandas as pd
import plotly.io as pio
pio.renderers.default = "notebook"
# os.chdir("...")

# Set time periods
dt.time(2024, 2060)
os.getcwd()
# Read grundforløb and shock gdx files
r = dt.REFERENCE_DATABASE = dt.Gdx("./Gdx/deep_calibration.gdx")
shock_name = "Arbejdsudbud_timer_ufin"
s = dt.Gdx(f"./Gdx/{shock_name}.gdx")
output_dir = f"Output/{shock_name}"
output_extension = ".svg"

DA = True # Should labels be in Danish or English? 


"""
List of tuples each containing information about a figure to plot. Each tuple contains:
(
    <Danish name for the figure>,
    <English name for the figure>,
    <A dictionary with Danish information about the lines to plot for the baseline>,
    <A dictionary with English information about the lines to plot for the baseline>,
    <multiplier type (operator)>,
    <Danish y-axis label (optional)>,
    <English y-axis label (optional)>,
)
"""
plot_info = [
  ("Forsyningsbalance real", "Supply balance real",
  {
  "Bruttonationalprodukt (qBNP)": lambda s: s.qBNP,
  "Privat forbrug (qC)": lambda s: s.qC["cTot"],
  "Offentligt forbrug (qG)": lambda s: s.qG["gTot"],
  "Investeringer (qI)": lambda s: s.qI["iTot"],
  "Eksport (qX)": lambda s: s.qX["xTot"],
  "Import (qM)": lambda s: s.qM["tot"],
  },
  {"Gross domestic product (qBNP)": lambda s: s.qBNP,
  "Private consumption (qC)": lambda s: s.qC["cTot"],
  "Public consumption (qG)": lambda s: s.qG["gTot"],
  "Investments (qI)": lambda s: s.qI["iTot"],
  "Exports (qX)": lambda s: s.qX["xTot"],
  "Imports (qM)": lambda s: s.qM["tot"],
  },
  "pq",
  "Pct.-ændring ift. BNP i grundforløb",
  "Pct. change relative to baseline",
  ),
  ("Forsyningsbalance værdier", "Values for supply balance",
  {
  "BNP (vBNP)": lambda s: s.vBNP,
  "Privat forbrug (vC)": lambda s: s.vC["cTot"],
  "Offentligt forbrug (vG)": lambda s: s.vG["gTot"],
  "Investeringer (vI)": lambda s: s.vI["iTot"],
  "Eksport (vX)": lambda s: s.vX["xTot"],
  "Import (vM)": lambda s: s.vM["tot"],
  },
  {
  "Gross domestic product (vBNP)": lambda s: s.vBNP,
  "Private consumption (vC)": lambda s: s.vC["cTot"],
  "Public consumption (vG)": lambda s: s.vG["gTot"],
  "Investments (vI)": lambda s: s.vI["iTot"],
  "Exports (vX)": lambda s: s.vX["xTot"],
  "Imports (vM)": lambda s: s.vM["tot"],
  },
  "pq",
  "Pct.-ændring i grundforløb",
  "Pct. change in baseline",
  ),
  ("Forsyningsbalance priser", "Supply balance prices",
  {
  "BNP (pBNP)": lambda s: s.pBNP,
  "Privat forbrug (pC)": lambda s: s.pC,
  "Offentligt forbrug (pG)": lambda s: s.pG,
  "Investeringer (pI)": lambda s: s.pI,
  "Eksport (pX)": lambda s: s.pX,
  "Import (pM)": lambda s: s.pM,
  },
  {
  "Gross domestic product (pBNP)": lambda s: s.pBNP,
  "Private consumption (pC)": lambda s: s.pC,
  "Public consumption (pG)": lambda s: s.pG,
  "Investments (pI)": lambda s: s.pI,
  "Exports (pX)": lambda s: s.pX,
  "Imports (pM)": lambda s: s.pM,
  },
  "pq",
  "Pct.-ændring i grundforløb",
  "Pct. change in baseline",
  ),
  ("Priser og løn", "Prices and wages",
  {
  "Privatsektor-outputpris (pY[spTot])": lambda s: s.pY.loc[["spTot"]],
  "Forbrugerpis (pC)": lambda s: s.pC,
  "Deflator på offentligt forbrug (pG)": lambda s: s.pG,
  "Eksportpris (pX)": lambda s: s.pX,
  "Timeløn (vhW)": lambda s: s.vhW,
  },
  {
  "Private sector output price (pY[spTot])": lambda s: s.pY.loc[["spTot"]],
  "Consumer price (pC)": lambda s: s.pC,
  "Deflator on public consumption (pG)": lambda s: s.pG,
  "Export price (pX)": lambda s: s.pX,
  "Wage (vhW)": lambda s: s.vhW,
  },
  "pq",
  "Pct.-ændring i grundforløb",
  "Pct. change in baseline",),
  ("Priser og løn private brancher", "Prices and wages private sectors",
  {
  "Privatsektor-outputpris (pY[spTot])": lambda s: s.pY.loc[["spTot"]],
  "Forbrugerpis (pC)": lambda s: s.pC,
  "Eksportpris (pX)": lambda s: s.pX,
  "Timeløn (vhW)": lambda s: s.vhW,
  },
  {
  "Private sector output price (pY[spTot])": lambda s: s.pY.loc[["spTot"]],
  "Consumer price (pC)": lambda s: s.pC,
  "Export price (pX)": lambda s: s.pX,
  "Wage (vhW)": lambda s: s.vhW,
  },
  "pq",
  "Pct.-ændring ift. grundforløb",
  "Pct. change relative to baseline",
  ),
  ("Beskæftigelse", "Employment",
  {
  "Beskæftigede (nL)": lambda s: s.nL,
  "Strukturelt beskæftigede (snL)": lambda s: s.snL,
  "Netto arbejdsstyrke (nNettoArbsty)": lambda s: s.nNettoArbsty,
  "Nettoledige (nNettoLedig)": lambda s: s.nNettoLedig,
  },
  {
  "Employed (nL)": lambda s: s.nL,
  "Structurally employed (snL)": lambda s: s.snL,
  "Net labour force (nNettoArbsty)": lambda s: s.nNettoArbsty,
  "Net unemployed (nNettoLedig)": lambda s: s.nNettoLedig,
  },
  "pq",
  "Pct.-ændring ift. grundforløb",
  "Pct. change relative to baseline",),
  ("Boligmarked", "Housing market",
  {
  "Boligpris (pBolig)": lambda s: s.pBolig,
  "Boliginvesteringer (qIBolig)": lambda s: s.qIBolig,
  },
  {
  "Housing price (pBolig)": lambda s: s.pBolig,
  "Housing investments (qIBolig)": lambda s: s.qIBolig,
  },
  "pq",
  "Pct.-ændring ift. grundforløb",
  "Pct. change relative to baseline",),
  ("Forbrug og bolig", "Consumption and housing",
  {
  "Privat forbrug ekskl. bolig (qC[Cx])": lambda s: s.qC.loc[["Cx"]],
  "Ejerbolig (qBolig)": lambda s: s.qBolig,
  },
  {
  "Private consumption excl. housing (qC[Cx])": lambda s: s.qC.loc[["Cx"]],
  "Owner-occupied housing (qBolig)": lambda s: s.qBolig,
  },
  "pq",
  "Pct.-ændring ift. grundforløb",
  "Pct. change relative to baseline",),
  ("Husholdningernes budget", "Household budget",
  {
  "Husholdningernes løbende indkomst efter skat (vHhInd)": lambda s: s.vHhInd,
  "Husholdningernes kapitalindkomst ekskl. bolig, realkredit og pension (vHhxAfk)": lambda s: s.vHhxAfk,
  "Udgift til (indtægt fra) ejerbolig inkl. optagelse af gæld og kapitalgevinster (vBoligUdgift)": lambda s: s.vBoligUdgift,
  "Privat forbrug ekskl. bolig i løbende priser (vC[Cx])": lambda s: s.vC.loc[["Cx"]],
  },
  {
  "Household disposable income after taxes (vHhInd)": lambda s: s.vHhInd,
  "Household capital income excl. housing, mortgage and pension (vHhxAfk)": lambda s: s.vHhxAfk,
  "Expenditure on (income from) owner-occupied housing incl. debt and capital gains (vBoligUdgift)": lambda s: s.vBoligUdgift,
  "Private consumption excl. housing in current prices (vC[Cx])": lambda s: s.vC.loc[["Cx"]],
  },
  "pq",
  "Pct.-ændring ift. grundforløb",
  "Pct. change relative to baseline",),
  ("Husholdningernes formue", "Household wealth",
  {
  "Samlet formue inklusiv bolig (vHhFormue)": lambda s: s.vHhFormue,
  "Formue ekskl. pension og realkreditgæld (vHhx)": lambda s: s.vHhx,
  "Ejerboligformue (vBolig)": lambda s: s.vBolig,
  # "Pensionsformue (vHh[Pens])": lambda s: s.vHh.loc[["Pens"],["tot"]],
  # "Pensionsformue (vHh[RealKred])": lambda s: s.vHh.loc[["RealKred"],["tot"]],
  },
  {
  "Total wealth incl. housing (vHhFormue)": lambda s: s.vHhFormue,
  "Wealth excl. pension and mortgage debt (vHhx)": lambda s: s.vHhx,
  "Owner-occupied housing wealth (vBolig)": lambda s: s.vBolig,
  # "Pension wealth (vHh[Pens])": lambda s: s.vHh.loc[["Pens"],["tot"]],
  # "Pension wealth (vHh[RealKred])": lambda s: s.vHh.loc[["RealKred"],["tot"]],
  },
  "pq",
  "Pct.-ændring ift. grundforløb",
  "Pct. change relative to baseline",),
  ("Investeringer", "Investments",
  {
  "Erhvervsinvesteringer i maskiner (qI_s[iM,spTot])": lambda s: s.qI_s["iM","spTot"],
  "Erhvervsinvesteringer i bygninger (qI_s[iB,spTot])": lambda s: s.qI_s["iB","spTot"],
  "Boliginvesteringer (qI_s[iB,spTot])": lambda s: s.qI_s["iB","bol"],
  "Offentlige investeringer (qI_s[iTot,off])": lambda s: s.qI_s["iTot","off"],
  },
  {
  "Business investments in machinery (qI_s[iM,spTot])": lambda s: s.qI_s["iM","spTot"],
  "Business investments in buildings (qI_s[iB,spTot])": lambda s: s.qI_s["iB","spTot"],
  "Housing investments (qI_s[iB,spTot])": lambda s: s.qI_s["iB","bol"],
  "Public investments (qI_s[iTot,off])": lambda s: s.qI_s["iTot","off"],                                
  },
  "pq",
  "Pct.-ændring ift. grundforløb",
  "Pct. change relative to baseline",),
  ("Offentligt budget", "Public budget",
  {
  "Offentlig primær saldo (vPrimSaldo)": lambda s: s.vPrimSaldo,
  "Offentligt forbrug i løbende priser (vG)": lambda s: s.vG,
  "Primære offentlige indtægter (vOffPrimInd)": lambda s: s.vOffPrimInd,
  "Primære offentlige udgifter (vOffPrimUd)": lambda s: s.vOffPrimUd,
  },
  {
  "Public primary balance (vPrimSaldo)": lambda s: s.vPrimSaldo,
  "Public consumption in current prices (vG)": lambda s: s.vG,
  "Primary public revenues (vOffPrimInd)": lambda s: s.vOffPrimInd,
  "Primary public expenditures (vOffPrimUd)": lambda s: s.vOffPrimUd,
  },
  "m",
  "Total ændring ift grundforløb",
  "Total change relative to baseline",),
  ("Holdbarhedsindikator", "Sustainability indicator",
  {
  "Holdbarhedsindikator (rHBI)": lambda s: s.rHBI,
  },
  {
  "Sustainability indicator (rHBI)": lambda s: s.rHBI,
  },
  "m",
  "Total ændring ift. grundforløb",
  "Total change relative to baseline",),
  ("Andel af produktionsværdi fordelt på brancher", "Share of value added distributed by sectors",
  {
  "Andel af produktionsværdi for tjenester (vY[tje]/vY[tot])": lambda s: s.vY["tje"] / s.vY["tot"],
  "Andel af produktionsværdi for fremstilling (vY[fre]/vY[tot])": lambda s: s.vY["fre"] / s.vY["tot"],
  "Andel af produktionsværdi for bygge og anlæg (vY[byg]/vY[tot])": lambda s: s.vY["byg"] / s.vY["tot"],
  "Andel af produktionsværdi for landbrug (vY[lan]/vY[tot])": lambda s: s.vY["lan"] / s.vY["tot"],
  "Andel af produktionsværdi for søtransport (vY[soe]/vY[tot])": lambda s: s.vY["soe"] / s.vY["tot"],
  "Andel af produktionsværdi for bolig (vY[bol]/vY[tot])": lambda s: s.vY["bol"] / s.vY["tot"],
  "Andel af produktionsværdi for energi (vY[ene]/vY[tot])": lambda s: s.vY["ene"] / s.vY["tot"],
  "Andel af produktionsværdi for udvinding (vY[udv]/vY[tot])": lambda s: s.vY["udv"] / s.vY["tot"],
  "Andel af produktionsværdi for offentlig service (vY[off]/vY[tot])": lambda s: s.vY["off"] / s.vY["tot"],
  },
  {
  "Share of value added for services (vY[tje]/vY[tot])": lambda s: s.vY["tje"] / s.vY["tot"],
  "Share of value added for manufacturing (vY[fre]/vY[tot])": lambda s: s.vY["fre"] / s.vY["tot"],
  "Share of value added for construction (vY[byg]/vY[tot])": lambda s: s.vY["byg"] / s.vY["tot"],
  "Share of value added for agriculture (vY[lan]/vY[tot])": lambda s: s.vY["lan"] / s.vY["tot"],
  "Share of value added for sea transport (vY[soe]/vY[tot])": lambda s: s.vY["soe"] / s.vY["tot"],
  "Share of value added for housing (vY[bol]/vY[tot])": lambda s: s.vY["bol"] / s.vY["tot"],
  "Share of value added for energy (vY[ene]/vY[tot])": lambda s: s.vY["ene"] / s.vY["tot"],
  "Share of value added for extraction (vY[udv]/vY[tot])": lambda s: s.vY["udv"] / s.vY["tot"],
  "Share of value added for public service (vY[off]/vY[tot])": lambda s: s.vY["off"] / s.vY["tot"],
  },
  "pm",
  "Ændring i %-point ift. grundforløb",
  "Change in %-points relative to baseline",),
  ("Andel af arbejdstimer fordelt på brancher", "Share of worked hours distributed by sectors",
  {
  "Andel af erlagte arbejdstimer for tjenester (hL[tje]/hL[tot])": lambda s: s.hL["tje"] / s.hL["tot"],
  "Andel af erlagte arbejdstimer for fremstilling (hL[fre]/hL[tot])": lambda s: s.hL["fre"] / s.hL["tot"],
  "Andel af erlagte arbejdstimer for bygge og anlæg (hL[byg]/hL[tot])": lambda s: s.hL["byg"] / s.hL["tot"],
  "Andel af erlagte arbejdstimer for landbrug (hL[lan]/hL[tot])": lambda s: s.hL["lan"] / s.hL["tot"],
  "Andel af erlagte arbejdstimer for søtransport (hL[soe]/hL[tot])": lambda s: s.hL["soe"] / s.hL["tot"],
  "Andel af erlagte arbejdstimer for bolig (hL[bol]/hL[tot])": lambda s: s.hL["bol"] / s.hL["tot"],
  "Andel af erlagte arbejdstimer for energi (hL[ene]/hL[tot])": lambda s: s.hL["ene"] / s.hL["tot"],
  "Andel af erlagte arbejdstimer for udvinding (hL[udv]/hL[tot])": lambda s: s.hL["udv"] / s.hL["tot"],
  "Andel af erlagte arbejdstimer for offentlig service (hL[off]/hL[tot])": lambda s: s.hL["off"] / s.hL["tot"],
  },
  {
  "Share of worked hours for services (hL[tje]/hL[tot])": lambda s: s.hL["tje"] / s.hL["tot"],
  "Share of worked hours for manufacturing (hL[fre]/hL[tot])": lambda s: s.hL["fre"] / s.hL["tot"],
  "Share of worked hours for construction (hL[byg]/hL[tot])": lambda s: s.hL["byg"] / s.hL["tot"],
  "Share of worked hours for agriculture (hL[lan]/hL[tot])": lambda s: s.hL["lan"] / s.hL["tot"],
  "Share of worked hours for sea transport (hL[soe]/hL[tot])": lambda s: s.hL["soe"] / s.hL["tot"],
  "Share of worked hours for housing (hL[bol]/hL[tot])": lambda s: s.hL["bol"] / s.hL["tot"],
  "Share of worked hours for energy (hL[ene]/hL[tot])": lambda s: s.hL["ene"] / s.hL["tot"],
  "Share of worked hours for extraction (hL[udv]/hL[tot])": lambda s: s.hL["udv"] / s.hL["tot"],
  "Share of worked hours for public service (hL[off]/hL[tot])": lambda s: s.hL["off"] / s.hL["tot"],
  },
  "pm",
  "Ændring i %-point ift. grundforløb",
  "Change in %-points relative to baseline",),
  ("Beskæftigede branchefordelt", "Employment distributed by sectors",
  {
  "Beskæftigede i tjenester (nL[tje])": lambda s: s.nL["tje"],
  "Beskæftigede i fremstilling (nL[fre])": lambda s: s.nL["fre"],
  "Beskæftigede i bygge og anlæg (nL[byg])": lambda s: s.nL["byg"],
  "Beskæftigede i landbrug (nL[lan])": lambda s: s.nL["lan"],
  "Beskæftigede i søtransport (nL[soe])": lambda s: s.nL["soe"],
  "Beskæftigede i bolig (nL[bol])": lambda s: s.nL["bol"],
  "Beskæftigede i energi (nL[ene])": lambda s: s.nL["ene"],
  "Beskæftigede i udvinding (nL[udv])": lambda s: s.nL["udv"],
  "Beskæftigede i offentlig service (nL[off])": lambda s: s.nL["off"],
  },
  {
  "Employed in services (nL[tje])": lambda s: s.nL["tje"],
  "Employed in manufacturing (nL[fre])": lambda s: s.nL["fre"],
  "Employed in construction (nL[byg])": lambda s: s.nL["byg"],
  "Employed in agriculture (nL[lan])": lambda s: s.nL["lan"],
  "Employed in sea transport (nL[soe])": lambda s: s.nL["soe"],
  "Employed in housing (nL[bol])": lambda s: s.nL["bol"],
  "Employed in energy (nL[ene])": lambda s: s.nL["ene"],
  "Employed in extraction (nL[udv])": lambda s: s.nL["udv"],
  "Employed in public service (nL[off])": lambda s: s.nL["off"],
  },
  "m",
  "Total ændring ift. grundforløb",
  "Total change relative to baseline",
  ),
  ("Arbejdstimer branchefordelt", "Worked hours distributed by sectors", 
  {
  "Arbejdstimer i tjenester (hL[tje])": lambda s: s.hL["tje"],
  "Arbejdstimer i fremstilling (hL[fre])": lambda s: s.hL["fre"],
  "Arbejdstimer i bygge og anlæg (hL[byg])": lambda s: s.hL["byg"],
  "Arbejdstimer i landbrug (hL[lan])": lambda s: s.hL["lan"],
  "Arbejdstimer i søtransport (hL[soe])": lambda s: s.hL["soe"],
  "Arbejdstimer i bolig (hL[bol])": lambda s: s.hL["bol"],
  "Arbejdstimer i energi (hL[ene])": lambda s: s.hL["ene"],
  "Arbejdstimer i udvinding (hL[udv])": lambda s: s.hL["udv"],
  "Arbejdstimer i offentlig service (hL[off])": lambda s: s.hL["off"],
  },
  {
  "Worked hours in services (hL[tje])": lambda s: s.hL["tje"],
  "Worked hours in manufacturing (hL[fre])": lambda s: s.hL["fre"],
  "Worked hours in construction (hL[byg])": lambda s: s.hL["byg"],
  "Worked hours in agriculture (hL[lan])": lambda s: s.hL["lan"],
  "Worked hours in sea transport (hL[soe])": lambda s: s.hL["soe"],
  "Worked hours in housing (hL[bol])": lambda s: s.hL["bol"],
  "Worked hours in energy (hL[ene])": lambda s: s.hL["ene"],
  "Worked hours in extraction (hL[udv])": lambda s: s.hL["udv"],
  "Worked hours in public service (hL[off])": lambda s: s.hL["off"],
  },
  "m",
  "Total ændring ift. grundforløb",
  "Total change relative to baseline",
  ),
  ("Produktion fordelt på brancher", "Production distributed by sectors",
  {
  "Produktion i tjenester (qY[tje])": lambda s: s.qY["tje"],
  "Produktion i fremstilling (qY[fre])": lambda s: s.qY["fre"],
  "Produktion i bygge og anlæg (qY[byg])": lambda s: s.qY["byg"],
  "Produktion i landbrug (qY[lan])": lambda s: s.qY["lan"],
  "Produktion i søtransport (qY[soe])": lambda s: s.qY["soe"],
  "Produktion i bolig (qY[bol])": lambda s: s.qY["bol"],
  "Produktion i energi (qY[ene])": lambda s: s.qY["ene"],
  "Produktion i udvinding (qY[udv])": lambda s: s.qY["udv"],
  "Produktion i offentlig service (qY[off])": lambda s: s.qY["off"],
  },
  {
  "Production in services (qY[tje])": lambda s: s.qY["tje"],
  "Production in manufacturing (qY[fre])": lambda s: s.qY["fre"],
  "Production in construction (qY[byg])": lambda s: s.qY["byg"],
  "Production in agriculture (qY[lan])": lambda s: s.qY["lan"],
  "Production in sea transport (qY[soe])": lambda s: s.qY["soe"],
  "Production in housing (qY[bol])": lambda s: s.qY["bol"],
  "Production in energy (qY[ene])": lambda s: s.qY["ene"],
  "Production in extraction (qY[udv])": lambda s: s.qY["udv"],
  "Production in public service (qY[off])": lambda s: s.qY["off"],
  },
  "m",
  "Total ændring ift. grundforløb",
  "Total change relative to baseline",
  ),
  ("Forsyningsbalance mængder", "Supply balance quantities",
  {
  "Bruttonationalprodukt i forhold til baseline (qBNP/qBNP)": lambda s, r: s.qBNP / r.qBNP,
  "Privat forbrug i forhold til baseline BNP (qC/qBNP)": lambda s, r: s.qC["cTot"] / r.qBNP,
  "Offentligt forbrug i forhold til baseline BNP (qG/qBNP)": lambda s, r: s.qG["gTot"] / r.qBNP,
  "Investeringer i forhold til baseline BNP (qI/qBNP)": lambda s, r: s.qI["iTot"] / r.qBNP,
  "Eksport i forhold til baseline BNP (qX/qBNP)": lambda s, r: s.qX["xTot"] / r.qBNP,
  "Import i forhold til baseline BNP (qM/qBNP)": lambda s, r: s.qM["tot"] / r.qBNP,
  },
  {
  "GDP relative to baseline (qBNP)": lambda s, r: s.qBNP / r.qBNP,
  "Private consumption relative to baseline GDP (qC/qBNP)": lambda s, r: s.qC["cTot"] / r.qBNP,
  "Public consumption relative to baseline GDP (qG/qBNP)": lambda s, r: s.qG["gTot"] / r.qBNP,
  "Investments relative to baseline GDP (qI/qBNP)": lambda s, r: s.qI["iTot"] / r.qBNP,
  "Exports relative to baseline GDP (qX/qBNP)": lambda s, r: s.qX["xTot"] / r.qBNP,
  "Imports relative to baseline GDP (qM/qBNP)": lambda s, r: s.qM["tot"] / r.qBNP,
  },
  "pm",
  "Ændring i %-point ift. grundforløb",
  "Change in %-points relative to baseline",),
  ("Forsyningsbalance værdier", "Supply balance values",
  {
  "Bruttonationalprodukt i forhold til baseline (qBNP/qBNP)": lambda s, r: s.qBNP / r.qBNP,
  "Privat forbrug i forhold til baseline BNP (vC/vBNP)": lambda s, r: s.vC["cTot"] / r.vBNP,
  "Offentligt forbrug i forhold til baseline BNP (vG/vBNP)": lambda s, r: s.vG["gTot"] / r.vBNP,
  "Investeringer i forhold til baseline BNP (vI/vBNP)": lambda s, r: s.vI["iTot"] / r.vBNP,
  "Eksport i forhold til baseline BNP (vX/vBNP)": lambda s, r: s.vX["xTot"] / r.vBNP,
  "Import i forhold til baseline BNP (vM/vBNP)": lambda s, r: s.vM["tot"] / r.vBNP,
  },
  {
  "GDP relative to baseline (vBNP)": lambda s, r: s.vBNP / r.vBNP,
  "Private consumption relative to baseline GDP (vC/vBNP)": lambda s, r: s.vC["cTot"] / r.vBNP,
  "Public consumption relative to baseline GDP (vG/vBNP)": lambda s, r: s.vG["gTot"] / r.vBNP,
  "Investments relative to baseline GDP (vI/vBNP)": lambda s, r: s.vI["iTot"] / r.vBNP,
  "Exports relative to baseline GDP (vX/vBNP)": lambda s, r: s.vX["xTot"] / r.vBNP,
  "Imports relative to baseline GDP (vM/vBNP)": lambda s, r: s.vM["tot"] / r.vBNP,
  },
  "pm",
  "Ændring i %-point ift. grundforløb",
  "Change in %-points relative to baseline",),
  ("Offentlig Produktion", "Public production",
  {
  "Offentlig produktion (qY[off])": lambda s: s.qY["off"],
  "Offentlige materialekøb (qR[off])": lambda s: s.qR["off"],
  "Offentlige kapitalafskrivninger (qOffAfskr[iTot])": lambda s: s.qOffAfskr["iTot"],
  "Offentlig beskæftigelse (hL[off])": lambda s: s.hL["off"],
  },
  {
  "Public production (qY[off])": lambda s: s.qY["off"],
  "Public material purchases (qR[off])": lambda s: s.qR["off"],
  "Public capital depreciation (qOffAfskr[iTot])": lambda s: s.qOffAfskr["iTot"],
  "Public employment (hL[off])": lambda s: s.hL["off"],
  },
"pq",
"Pct.-ændring ift. grundforløb",
"Pct. change relative to baseline",),
("Skattelettelse som andel af BNP", "Tax cut as share of GDP",
{
"Skattelettelse som andel af BNP (-vtLukning / vBNP)": lambda s: - s.vtLukning / s.vBNP,
},
{
"Tax cut as share of GDP (-vtLukning / vBNP)": lambda s: - s.vtLukning / s.vBNP,
},
"pm",
"Ændring i %-point ift. grundforløb",
"Change in %-points relative to baseline",),
("Befolkning", "Population",
{
"Befolkning (nPop)": lambda s: s.nPop,
},
{
"Population (nPop)": lambda s: s.nPop,
},
"pq",
"Pct.-ændring ift. grundforløb",
"Pct. change relative to baseline",),
("Løn", "Wages",
{
"Marginalt arbejdsprodukt (pL[spTot])": lambda s: (s.hL * s.qProd * s.pL).loc[s.sp].groupby(level=1).sum() / (s.hL * s.qProd).loc[s.sp].groupby(level=1).sum()* s.qProd['tot'],
"Løn i privat sektor (pW*qProd[tot])": lambda s: s.pW * s.qProd['tot'],
"Output-priser (pY)": lambda s: s.pY['tot'],
"Forbrugerpriser (pC)": lambda s: s.pC['cTot'],
},
{
"Marginal labour productivity (pL[spTot])": lambda s: (s.hL * s.qProd * s.pL).loc[s.sp].groupby(level=1).sum() / (s.hL * s.qProd).loc[s.sp].groupby(level=1).sum()* s.qProd['tot'],
"Wages in the private sector (pW*qProd[tot])": lambda s: s.pW * s.qProd['tot'],
"Output prices (pY)": lambda s: s.pY['tot'],
"Consumer prices (pC)": lambda s: s.pC['cTot'],
},
"pq",
"Pct.-ændring ift. grundforløb",
"Pct. change relative to baseline",),
("Priser", "Prices",
{
"BNP-deflator (pBNP)": lambda s: s.pBNP,
"Forbrugerpriser (pC[cTot])": lambda s: s.pC['cTot'],
"Offentligt forbrugs-deflator (pG[gTot])": lambda s: s.pG['gTot'],
"Investeringspriser (pI[iTot])": lambda s: s.pI['iTot'],
"Eksportpriser (pX[xTot])": lambda s: s.pX['xTot'],
"Importpriser (pM[tot])": lambda s: s.pM['tot'],
},
{
"GDP deflator (pBNP)": lambda s: s.pBNP,
"Consumer prices (pC[cTot])": lambda s: s.pC['cTot'],
"Public consumption deflator (pG[gTot])": lambda s: s.pG['gTot'],
"Investment prices (pI[iTot])": lambda s: s.pI['iTot'],
"Export prices (pX[xTot])": lambda s: s.pX['xTot'],
"Import prices (pM[tot])": lambda s: s.pM['tot'],
},
"pq",
"Pct.-ændring ift. grundforløb",
"Pct. change relative to baseline",),
("Realløn", "Real wages",
{
"Marginalt arbejdsprodukt (pL[spTot])": lambda s: (s.hL * s.qProd * s.pL).loc[s.sp].groupby(level=1).sum() / (s.hL * s.qProd).loc[s.sp].groupby(level=1).sum()* s.qProd['tot'],
"Realløn (vhW/pC)": lambda s: s.vhW / s.pC[['cTot']],
"Gennemsnitlig timeløn (vhW)": lambda s: s.vhW,
"Forbrugerpriser (pC)": lambda s: s.pC['cTot'],
},
{
"Marginal labour productivity (pL[spTot])": lambda s: (s.hL * s.qProd * s.pL).loc[s.sp].groupby(level=1).sum() / (s.hL * s.qProd).loc[s.sp].groupby(level=1).sum()* s.qProd['tot'],
"Real wages (vhW/pC)": lambda s: s.vhW / s.pC[['cTot']],
"Average hourly wage (vhW)": lambda s: s.vhW,
"Consumer prices (pC)": lambda s: s.pC['cTot'],
},
"pq",
"Pct.-ændring ift. grundforløb",
"Pct. change relative to baseline",),
("Beskæftigelse", "Employment",
{
"Beskæftigede (nL)": lambda s: s.nL,
"Strukturelt beskæftigede (snL)": lambda s: s.snL,
"Netto arbejdsstyrke (nNettoArbsty)": lambda s: s.nNettoArbsty,
"Nettoledige (nNettoLedig)": lambda s: s.nNettoLedig,
},
{
"Employed (nL)": lambda s: s.nL,
"Structurally employed (snL)": lambda s: s.snL,
"Net labour force (nNettoArbsty)": lambda s: s.nNettoArbsty,
"Unemployed (nNettoLedig)": lambda s: s.nNettoLedig,
},
"m",
"Total ændring ift. grundforløb",
"Total change relative to baseline",),
("Offentligt budget", "Public budget",
{
"Offentlig primær saldo (vPrimSaldo/vBNP)": lambda s: s.vPrimSaldo / s.vBNP,
"Offentligt forbrug i løbende priser (vG/vBNP)": lambda s: s.vG / s.vBNP,
"Primære offentlige indtægter (vOffPrimInd/vBNP)": lambda s: s.vOffPrimInd / s.vBNP,
"Primære offentlige udgifter (vOffPrimUd/vBNP)": lambda s: s.vOffPrimUd / s.vBNP,
},
{
"Public primary balance (vPrimSaldo/vBNP)": lambda s: s.vPrimSaldo / s.vBNP,
"Public consumption in current prices (vG/vBNP)": lambda s: s.vG / s.vBNP,
"Primary public revenues (vOffPrimInd/vBNP)": lambda s: s.vOffPrimInd / s.vBNP,
"Primary public expenditures (vOffPrimUd/vBNP)": lambda s: s.vOffPrimUd / s.vBNP,
},
"pm",
"Ændring i %-point ift. grundforløb",
"Change in %-points relative to baseline",),
]

# Default yaxis labels based on operator
yaxis_title_from_operator = {
    "pq": "Pct. ændring",
    "pm": "Ændring i %-point",
    "m": "Total ændring",
    "": "",
} if DA else {
    "pq": "Pct. change",
    "pm": "Change in %-points",
    "m": "Total change",
    "": "",
}

# Unpack plot_info and select language
figure_name_DA, figure_name_EN, lines_info_DA, lines_info_EN, operator, yaxis_label_DA, yaxis_label_EN = [list(t) for t in zip(*plot_info)]
figure_name = figure_name_DA if DA else figure_name_EN
lines_info = lines_info_DA if DA else lines_info_EN
yaxis_label = yaxis_label_DA if DA else yaxis_label_EN

# dt.REFERENCE_DATABASE = dt.Gdx(r)
if not os.path.exists(output_dir):
    os.makedirs(output_dir)
for figure_name, lines_info, operator, yaxis_label in zip(
        figure_name,
        lines_info,
        operator,
        yaxis_label
    ):
    labels, functions = zip(*lines_info.items())
    if yaxis_label is None:
        yaxis_label = yaxis_title_from_operator[operator]
    df = dt.DataFrame(s, operator, functions=functions, names=labels)
    DPCM = 96 / 2.54
    plot_height = 6
    margin_b = 4
    fig = df.plot(layout=dict(
        title_text=f"<b>{figure_name}</b>",
        yaxis_title_text=yaxis_label,
        width = 12 * DPCM,
        height = (plot_height + margin_b) * DPCM,
        margin_l = 1.5 * DPCM,
        margin_r = 0.5 * DPCM,
        margin_t = 1 * DPCM,
        margin_b = margin_b * DPCM,
        legend_y = -0.25,
        xaxis_title_text = "År" if DA else "Year",
    ), horizontal_yaxis_title=False)
    output_path = f"{output_dir}/{figure_name}{output_extension}"
    dt.write_image(fig, output_path)